package com.tp.checkly.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tp.checkly.dao.ChecklistDao;
import com.tp.checkly.domain.Task;

@Controller
@RequestMapping("/checklist")
public class ChecklistController {
	
	private ChecklistDao checklistDao;
	
	public ChecklistDao getChecklistDao() {
		return checklistDao;
	}

	public void setChecklistDao(ChecklistDao checklistDao) {
		this.checklistDao = checklistDao;
	}

	@RequestMapping(value="/{user}", method = RequestMethod.GET)
	public @ResponseBody List<Task> getChecklist(@PathVariable("user") String userid)
	{
		List<Task> tasks = checklistDao.getChecklist(userid);
		return tasks;
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public @ResponseBody void saveChecklist(@RequestBody Task[] tasks)
	{
		checklistDao.saveChecklist(Arrays.asList(tasks));
	}

}
